#include "stdafx.h"
#include "prop_mgr.h"


prop_mgr_x::prop_mgr_x()
{

}

prop_mgr_x::~prop_mgr_x()
{

}

void prop_mgr_x::GetPropMap( prop_map& props )
{
    props = m_props;
}

bool prop_mgr_x::AddProp( prop_index id, prop_nums nums /*= 1*/ )
{
    prop_map::iterator it = m_props.find(id);
    if (it != m_props.end())
    {
        it->second += nums;
    }
    else
    {
        m_props[id] = nums;
    }
    return true;
}

bool prop_mgr_x::RemoveProp( prop_index id, prop_nums nums /*= 1*/ )
{
    bool bRet = false;
    prop_map::iterator it = m_props.find(id);
    if (it != m_props.end())
    {
        if (it->second > nums)
        {
            it->second -= nums;
            bRet = true;
        }
        else if (it->second == nums)
        {
            m_props.erase(it);
            bRet = true;
        }
    }
    return bRet;
}

bool prop_mgr_x::HasProp( prop_index id, prop_nums nums /*= 1*/ )
{
    prop_map::iterator it = m_props.find(id);
    if (it != m_props.end())
    {
        if (it->second >= nums)
        {
            return true;
        }
    }
    return false;
}

bool prop_mgr_x::GetPropNums( prop_index id, prop_nums& nums )
{
    prop_map::iterator it = m_props.find(id);
    if (it != m_props.end())
    {
        nums = it->second;
        return true;
    }
    return false;
}

